var suggest = require('../../../public/suggest');

return function(elem, data){
    var that = this;
    elem.suggest(extend(suggest, {
        zindex:that.layer ? that.layer._zIndex : null,
        offset:{
            top:4
        },
        returnData:function(data, index){
            return '<li data-index='+index+'>'+ data.buname +'</li>';
        },
        getData:function(keywords){
            if(keywords === true){
                return data
            }
            var list = [], kw = Nui.trim(keywords);
            Nui.each(data, function(val, key){
                if(val.buname.indexOf(kw) !==- 1){
                    list.push(data[key]);
                }
            });
            return list;
        },
        eventEnd:function(item, ele){
            that.data.subject_index = item.data('index');
            that.data.subject = data[that.data.subject_index];
            that._query(ele);
        }
    }))
}